package pos.data;

import pos.domain.Service;

import pos.utils.*;

import java.sql.*;
import java.util.*;

public class JDBCServiceDAO implements IServiceDAO {
	public List<Service> listabusqueda;
	public void delete(String propertyOID) {
		String sql= "DELETE FROM Service WHERE (propertyID= ?)";
		PreparedStatement stmt=null;
		
		
		
	}

	public void insert(Connection conn ,String propertyID, Service s) {
		String sql= "INSERT into Service (propertyID,airConditioning,heating,washingMachine,tv,dishwasher,oven,hearth,elevator,garage,pool,terrace,smoker,carSharing,animals) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
		PreparedStatement stmt= null;
		BooleanAString b=new BooleanAString();
		try{
			stmt = conn.prepareStatement(sql);
			stmt.setString(1,propertyID);
			stmt.setString(2,b.exp(s.isAirConditioning()));
			stmt.setString(3,b.exp(s.isHeating()));
			stmt.setString(4,b.exp(s.isWashingMachine()));
			stmt.setString(5,b.exp(s.isTv()));
			stmt.setString(6,b.exp(s.isDishwasher()));
			stmt.setString(7,b.exp( s.isOven()));
			stmt.setString(8,b.exp( s.isHearth()));
			stmt.setString(9,b.exp( s.isElevator()));
			stmt.setString(10,b.exp( s.isGarage()));
			stmt.setString(11,b.exp( s.isPool()));
			stmt.setString(12,b.exp( s.isTerrace()));
			stmt.setString(13,b.exp( s.isSmoker()));
			stmt.setString(14,b.exp( s.isCarSharing()));
			stmt.setString(15,b.exp( s.isAnimals()));
			
			/*System.out.println("service dentro de JDBC:");
			System.out.println(propertyID);
			System.out.println(b.exp(s.isAirConditioning()));
			System.out.println(b.exp(s.isHeating()));
			System.out.println(b.exp(s.isWashingMachine()));
			System.out.println(b.exp(s.isTv()));
			System.out.println(b.exp(s.isDishwasher()));
			System.out.println(b.exp( s.isOven()));
			System.out.println(b.exp( s.isHearth()));
			System.out.println(b.exp( s.isElevator()));
			System.out.println(b.exp( s.isGarage()));
			System.out.println(b.exp( s.isPool()));
			System.out.println(b.exp( s.isTerrace()));
			System.out.println(b.exp( s.isSmoker()));
			System.out.println(b.exp( s.isCarSharing()));
			System.out.println(b.exp( s.isAnimals()));
			*/
			
			
			
			
			
			
			
			
			int i=stmt.executeUpdate();
			System.out.println("rows en service:"+i);
			
			
			
		}catch (SQLException e) {
            System.out.println("Message: " + e.getMessage());
            System.out.println("SQLState: " + e.getSQLState());
            System.out.println("ErrorCode: " + e.getErrorCode());
        } finally {
            try {
                if (stmt != null) {
                    stmt.close();
                }
            } catch (SQLException e) {
            }
	}
	}
	
	public Service selectPropertyByFields(Connection conn,List<Boolean> query, String PropertyID)
		{	
			Service s= selectService(PropertyID,conn);
			System.out.println("s="+s.toString());
			if(s.isAirConditioning()==query.get(0) && s.isHeating()==query.get(1) && s.isTv()==query.get(2) &&
					s.isElevator()==query.get(3)&& s.isPool()==query.get(4) && s.isSmoker()==query.get(5) &&
					s.isAnimals()==query.get(6) && s.isCarSharing()==query.get(7)){
				return s;	
			}else return null;
		}

	public boolean checkService(Connection conn, String ServiceID1,
			String ServiceID2) {
		// TODO Auto-generated method stub
		return false;
	}

	public Service selectService(String propertyID, Connection conn) {
		Service service = new Service();
		String sql = "SELECT * FROM Service WHERE propertyID = ?;";
		StringABoolean bs=new StringABoolean();
		PreparedStatement stmt = null;
		ResultSet result = null;
		try {
			stmt = conn.prepareStatement(sql);
			stmt.setString(1, propertyID);
			result = stmt.executeQuery();
			result.next();
			service.setAirConditioning(bs.exp(result.getString("airConditioning")));
			service.setAnimals(bs.exp(result.getString("animals")));
			service.setCarSharing(bs.exp(result.getString("carSharing")));
			service.setDishwasher(bs.exp(result.getString("dishwasher")));
			service.setElevator(bs.exp(result.getString("elevator")));
			service.setGarage(bs.exp(result.getString("garage")));
			service.setHearth(bs.exp(result.getString("hearth")));
			service.setHeating(bs.exp(result.getString("heating")));
			service.setOven(bs.exp(result.getString("oven")));
			service.setPool(bs.exp(result.getString("pool")));
			service.setServiceID(result.getString("propertyID"));
			service.setSmoker(bs.exp(result.getString("smoker")));
			service.setTerrace(bs.exp(result.getString("terrace")));
			service.setTv(bs.exp(result.getString("tv")));
			service.setWashingMachine(bs.exp(result.getString("washingMachine")));
    
    
			
    
		} catch (SQLException e) {
			System.out.println("Message: " + e.getMessage());
			System.out.println("SQLState: " + e.getSQLState());
			System.out.println("ErrorCode: " + e.getErrorCode());
		} finally {
			try {
				if (result != null) {
					result.close();
				}
        if (stmt != null) {
            stmt.close();
        }
    } catch (SQLException e) {
    }
}




		return service;
	}
	}

